<?php
class authActions extends sfGraduaActions
{
    function executeIndex($request) {
        $this->setLayout('layoutTasks');
    }

    function executeLogout($request) {
        AuthService::logout();
        $this->redirect('@homepage');
    }

    function executeLoginAction($request) {
        if($this->getRequest()->isXmlHttpRequest()) {
            $this->forward($this->getModuleName(),'showLogin');
        }
        else {
            $this->redirect($this->getModuleName().'/index');
        }
    }

    function executeSecurityAction($request) {
        Dbg::x("securityAction");
    }

    function executeShowNavData($request) {
        sfLoader::loadHelpers(array('Partial','Php2Js'));
        $this
          ->getResponseJsCall()
          ->addCommand('auth','displayMainMenu')
          ->addPHPParam(
              'data',
              component2Js(
                  'globalPartials',
                  'nav',
                  array(),
                  false
              )
          );
        return sfView::NONE;
    }

    function executeShowLogin($request) {
        sfLoader::loadHelpers(array('Partial','Php2Js'));
        $this
            ->getResponseJsCall()
            ->displayDialog(
                partial2Js(
                    'auth/login',
                    array(),
                    false
                )
            );
        return sfView::NONE;
    }


    function executeLogin($request) {
        $obj = $this->getObjRequest('auth');
        try {
            AuthService::login($obj);
            $this->getResponseJsCall()->closeDialog();
            $this->forward($this->getModuleName(), 'showNavData');
        }
        catch(InvalidUserAndPasswordException $e) {
            $this->getResponseJsCall()->showFeedback('Invalid User and Password');
        }
        return sfView::NONE;
    }

}
?>
